package com.exam.danangtranel.adapter;

import java.util.ArrayList;

import com.exam.danangtranel.filed.Contact;
import com.example.danangtravel.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TbLienHeAdapter extends BaseAdapter {
	private Context context;
	public ArrayList<Contact> array;
	private LayoutInflater inflater;
	static Contact data;
	
	public TbLienHeAdapter(Context context, ArrayList<Contact> arrayList) {
		this.context = context;
		this.array = arrayList;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return array.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return array.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	static class ViewHolder {
		TextView lienheName, lienheMail, lienhePhone;

	}
	public View getView(int position, View convertView, ViewGroup parent) {
		data = array.get(position);
		ViewHolder holder;
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.row_lienhe, null);
			holder.lienheName = (TextView) convertView
					.findViewById(R.id.name);
			holder.lienheMail = (TextView) convertView
					.findViewById(R.id.mail);
			holder.lienhePhone = (TextView) convertView
					.findViewById(R.id.phone);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.lienheName.setText(data.getName());
		holder.lienheMail.setText(data.getMail());
		holder.lienhePhone.setText(data.getPhone());
		return convertView;
	}
			
}